using System;
using System.Windows.Forms;
using FlexCell;
using Infragistics.Win.UltraWinTabControl;
using PluginFrame;

namespace PcrExperimentProject
{
	public class FormGeneScanProjectEditor : FormProjectEditor
	{
		private IGeneScanPcrExperimentProject mHRMProject;

		public FormGeneScanProjectEditor(IApplication application, IPcrExperimentProject pcrExperimentProject, bool isNewPcrProject, bool isAllowToChangeChannelSettings)
			: base(application, pcrExperimentProject, isNewPcrProject, isAllowToChangeChannelSettings)
		{
			tabPcrProject.Tabs["Cross Talk"].Visible = false;
			tabPcrProject.Tabs["Rule"].Visible = false;
			UltraTabControl ultraTabControl = pnlAnalysisOption.Controls[0] as UltraTabControl;
			if (ultraTabControl != null)
			{
				UltraTabControl ultraTabControl2 = ultraTabControl.Tabs[0].TabPage.Controls["Options Tab Control"] as UltraTabControl;
				Control control = ultraTabControl2.Tabs[mPcrExperimentProject.Name + " Basic Option"].TabPage.Controls[mPcrExperimentProject.Name + " Basic Option Grid"];
				Grid val = (Grid)(object)((control is Grid) ? control : null);
				val.Column(7).Visible = false;
			}
		}

		protected override void InitializeMeltingSegment()
		{
			grbMeltingSegment.Visible = false;
			chkMeltingSegment.Visible = false;
		}

		protected override void InitializeHRMSegment()
		{
			numHRMStartTemperature.DecimalPlaces = 1;
			numHRMStopTemperature.DecimalPlaces = 1;
			numHRMStartTemperature.Maximum = Convert.ToDecimal(mPcrProgramConfiguration.MaxTemperature);
			numHRMStartTemperature.Minimum = Convert.ToDecimal(mPcrProgramConfiguration.MinTemperature);
			numHRMStopTemperature.Maximum = Convert.ToDecimal(mPcrProgramConfiguration.MaxTemperature);
			numHRMStopTemperature.Minimum = Convert.ToDecimal(mPcrProgramConfiguration.MinTemperature);
			numHRMStartTemperature.Value = 60m;
			numHRMStopTemperature.Value = 90m;
			cmbHRMInterval.Items.Add("0.1");
			cmbHRMInterval.Items.Add("0.2");
			cmbHRMInterval.Items.Add("0.3");
			cmbHRMInterval.SelectedIndex = 0;
			cmbHRMRate.Items.Add("0.01");
			cmbHRMRate.Items.Add("0.02");
			cmbHRMRate.Items.Add("0.03");
			cmbHRMRate.Items.Add("0.04");
			cmbHRMRate.Items.Add("0.05");
			cmbHRMRate.SelectedIndex = 0;
			cmbHRMMode.Items.Add("Continue");
			cmbHRMMode.Items.Add("Step");
			cmbHRMMode.SelectedIndex = 0;
			numHRMHoldTime.Value = mMiscService.CovertTimeStringToSecond(mConfigurationService.HRMHoldTime);
			chkHRMSegment.Checked = false;
			SetHRMSegmentEnabled(true);
			cmbHRMMode.SelectedIndexChanged += cmbHRMMode_SelectedIndexChanged;
			cmbHRMInterval.SelectedIndexChanged += base.cmbHRMInterval_SelectedIndexChanged;
			cmbHRMRate.SelectedIndexChanged += base.cmbHRMRate_SelectedIndexChanged;
			numHRMHoldTime.ValueChanged += base.numHRMHoldTime_ValueChanged;
			numHRMStopTemperature.ValueChanged += base.numHRMStopTemperature_ValueChanged;
			numHRMStartTemperature.ValueChanged += base.numHRMStartTemperature_ValueChanged;
			grbHRMSegment.Visible = true;
		}

		protected void SetHRMMode(HRMModeEnum hrmMode)
		{
			cmbHRMRate.Visible = hrmMode.Equals(HRMModeEnum.Continue);
			lblHRMRate.Visible = hrmMode.Equals(HRMModeEnum.Continue);
			cmbHRMInterval.Visible = !hrmMode.Equals(HRMModeEnum.Continue);
			lblHRMInterval.Visible = cmbHRMInterval.Visible;
			lblHRMHoldTime.Visible = cmbHRMInterval.Visible;
			numHRMHoldTime.Visible = cmbHRMInterval.Visible;
		}

		protected override bool SaveMeltingSegment()
		{
			if (CheckHRMSegment())
			{
				mHRMSegment.IsAvailable = true;
				if (mHRMSegment.IsAvailable)
				{
					mHRMProject.HRMMode = (HRMModeEnum)cmbHRMMode.SelectedIndex;
					mHRMProject.SettingRate = Convert.ToDouble(cmbHRMRate.Text);
					mHRMSegment.StartDegree = Convert.ToDouble(numHRMStartTemperature.Value);
					mHRMSegment.StopDegree = Convert.ToDouble(numHRMStopTemperature.Value);
					mHRMSegment.StepInterval = Convert.ToDouble(cmbHRMInterval.Text);
					if (mHRMProject.HRMMode == HRMModeEnum.Continue)
					{
						mHRMSegment.Rate = mHRMProject.SettingRate;
						mHRMSegment.HoldTime = "00:10";
					}
					else
					{
						mHRMSegment.HoldTime = "00:" + numHRMHoldTime.Value.ToString("00");
						mHRMSegment.Rate = 0.0;
					}
					mHRMSegment.Index = 10;
				}
				return true;
			}
			return false;
		}

		protected override void RefreshMeltingSegmentDisplay()
		{
			bool isAvailable = mHRMSegment.IsAvailable;
			chkHRMSegment.Checked = true;
			try
			{
				numHRMStartTemperature.Value = (decimal)mHRMSegment.StartDegree;
				numHRMStopTemperature.Value = Convert.ToDecimal(mHRMSegment.StopDegree);
				cmbHRMInterval.Text = mHRMSegment.StepInterval.ToString();
				mHRMProject = (IGeneScanPcrExperimentProject)mPcrExperimentProject;
				numHRMHoldTime.Value = mMiscService.CovertTimeStringToSecond(mHRMSegment.HoldTime);
				if (mHRMProject != null)
				{
					cmbHRMMode.SelectedIndex = (int)mHRMProject.HRMMode;
					cmbHRMRate.Text = mHRMProject.SettingRate.ToString();
				}
				SetHRMMode((HRMModeEnum)cmbHRMMode.SelectedIndex);
			}
			catch (Exception)
			{
			}
		}

		protected override UltraTabControl IntializeAnalysisOptionTabControl()
		{
			UltraTabControl ultraTabControl = base.IntializeAnalysisOptionTabControl();
			UltraTabControl ultraTabControl2 = ultraTabControl.Tabs[0].TabPage.Controls["Options Tab Control"] as UltraTabControl;
			if (ultraTabControl2.Tabs.Exists(mPcrExperimentProject.Name + " HRM Option"))
			{
				Control control = ultraTabControl2.Tabs[mPcrExperimentProject.Name + " HRM Option"].TabPage.Controls[mPcrExperimentProject.Name + " HRM Option Grid"];
			}
			return ultraTabControl;
		}

		protected override void RefreshAnalysisTabControl(UltraTabControl analysisTabControl, string oldTabName)
		{
			if (analysisTabControl != null)
			{
				analysisTabControl.Tabs[oldTabName + " Basic Option"].Key = mPcrExperimentProject.Name + " Basic Option";
				mAnalysisService.RefreshBasicAnalysisOptionTab(analysisTabControl, mPcrExperimentProject);
				analysisTabControl.Tabs[oldTabName + " HRM Option"].Key = mPcrExperimentProject.Name + " HRM Option";
				mAnalysisService.RefreshMeltingAnalysisOptionTab(analysisTabControl, mPcrExperimentProject);
			}
		}

		private void cmbHRMMode_SelectedIndexChanged(object sender, EventArgs e)
		{
			try
			{
				SetHRMMode((HRMModeEnum)cmbHRMMode.SelectedIndex);
				mHRMProject.HRMMode = (HRMModeEnum)cmbHRMMode.SelectedIndex;
				IPcrProgram pcrProgram = mPcrExperimentProject.PcrProgram;
				pcrProgram.GetExperimentTotalTime(true);
				mPcrProjectService.DrawExperimentProgramCurve(chartPcrProgram, mPcrExperimentProject.PcrProgram, false, scrollBar, false, true);
			}
			catch (Exception ex)
			{
				mPcrLogService.ShowExceptionDialogBox(ex);
			}
		}

		protected override void tabPcrProject_SelectedTabChanged(object sender, SelectedTabChangedEventArgs e)
		{
			try
			{
				if (e.Tab.Key.Equals("Melting"))
				{
					SetHRMMode((HRMModeEnum)cmbHRMMode.SelectedIndex);
				}
			}
			catch (Exception ex)
			{
				mPcrLogService.ShowExceptionDialogBox(ex);
			}
		}
	}
}
